package com.pretty.adminapp.controller;

import com.pretty.adminapp.controller.restful.BaseController;
import com.pretty.adminapp.dao.um.MenuDao;
import com.pretty.adminapp.pojo.model.um.Employee;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 类描述：
 * 创建者：袁越
 * 创建日期：2017/3/31
 * 创建时间：22:34
 * Copyright:版权
 * © 2016-2020 上海金扳手科技信息股份有限公司 All rights reserved.
 */
@Controller
public class IndexController extends BaseController<Employee> {
    @ApiOperation(value = "/testFeign",notes = "测试Feign",httpMethod = "GET")
    @ApiParam(name = "content",value = "参数：content")
    @RequestMapping(value = {"/","/index",""})
    public String index(){
        return "index";
    }
    @RequestMapping("/login")
    public String login() {
        return "login";
    }
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('a','b')")
    @RequestMapping("/testMapper")
    public String testMapper(){

        return "index";
    }

    /**
     * unauthor
     * @return
     */
    @RequestMapping("unauthor")
    public String unauthor() {
        return "loginFailed";
    }

    /**
     * reports
     * @return
     */
    @RequestMapping("reports")
    public String reports() {
        return "reports.jsp";
    }

    /**
     * Go login
     * @param request
     * @return
     */
    @RequestMapping(value="login", method= RequestMethod.POST)
    public String login(HttpServletRequest request, RedirectAttributes rediect) {
//        String account = request.getParameter("username");
//        String password = request.getParameter("password");
//
//        UsernamePasswordToken upt = new UsernamePasswordToken(account, password);
//        Subject subject = SecurityUtils.getSubject();
//        try {
//            subject.login(upt);
//        } catch (AuthenticationException e) {
//            e.printStackTrace();
//            rediect.addFlashAttribute("errorText", "您的账号或密码输入错误!");
//            return "redirect:/login";
//        }
        return "login";
    }

    /**
     * Exit
     * @return
     */
    @RequestMapping("logout")
    public String logout() {
//        Subject subject = SecurityUtils.getSubject();
//        subject.logout();
        return "redirect:/index";
    }
}
